package com.black.web.controller.exercise;

import com.black.app.domain.req.exercise.add.AppExerciseActionAddReq;
import com.black.app.domain.req.exercise.edit.AppExerciseActionEditReq;
import com.black.app.domain.req.exercise.query.AppExerciseActionQueryReq;
import com.black.app.domain.resp.exercise.AdminExerciseActionGroupResp;
import com.black.app.domain.resp.exercise.AdminExerciseActionResp;
import com.black.app.service.exercise.AppExerciseActionService;
import com.black.common.annotation.Log;
import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.black.common.enums.BusinessType;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

@Api(tags = "后台-锻炼动作相关Api")
@RestController
@RequestMapping("/admin/exercise/action")
public class AdminExerciseActionController extends BaseController {

    @Autowired
    private AppExerciseActionService appExerciseActionService;

    @PreAuthorize("@ss.hasPermi('exercise:action:list')")
    @ApiOperation(value = "根据系列id获取对应的锻炼动作")
    @GetMapping("/list")
    public R<List<AdminExerciseActionGroupResp>> list(AppExerciseActionQueryReq req) {
        List<AdminExerciseActionGroupResp> list = this.appExerciseActionService.getBySId(req);
        return R.ok(list);
    }

    @PreAuthorize("@ss.hasPermi('exercise:action:query')")
    @ApiOperation(value = "根据id查询动作")
    @GetMapping("/{actionId}")
    public R<AdminExerciseActionResp> findById(@PathVariable Long actionId) {
        AdminExerciseActionResp action = this.appExerciseActionService.findById(actionId);
        return R.ok(action);
    }

    @Log(title = "添加动作", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('exercise:action:add')")
    @ApiOperation(value = "添加动作")
    @PostMapping
    public R add(@RequestBody @Valid AppExerciseActionAddReq req) {
        boolean flag = this.appExerciseActionService.add(req);
        return this.isSuccess(flag);
    }

    @Log(title = "修改动作", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('exercise:action:edit')")
    @ApiOperation(value = "修改动作")
    @PutMapping
    public R edit(@RequestBody @Valid AppExerciseActionEditReq req) {
        boolean flag = this.appExerciseActionService.edit(req);
        return this.isSuccess(flag);
    }

    @Log(title = "删除动作", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('exercise:action:remove')")
    @ApiOperation(value = "删除动作")
    @DeleteMapping("/{actionId}")
    public R delete(@PathVariable Long actionId) {
        boolean flag = this.appExerciseActionService.removeById(actionId);
        return this.isSuccess(flag);
    }
}
